using System;
using System.Runtime.Serialization;
using MiniStock.Entities.Common;
using MiniStock.Entities.Common.Events;
using MiniStock.Entities.Stock.Events.Customer;

namespace MiniStock.Entities.Stock.Events.Product
{
    [DataContract]
    [KnownType(typeof(CreateProductEvent))]
    [KnownType(typeof(ChangeProductManufacturerEvent))]
    [KnownType(typeof(ChangeProductDescriptionEvent))]
    public abstract class ProductEventBase : EntityEventBase
    {
        [DataMember]
        public Guid Id { get; set; }

        public override void ApplyTo(EntityBase entity)
        {
            if (entity != null && !(entity is Stock.Product))
                throw new ApplicationException("Event is only valid for products");
        }

        public override bool IsConstructionMessage
        {
            get { return this is CreateProductEvent; }
        }

        public override string GetEntityHash()
        {
            return "Product|" + Id;
        }

        public override Type GetEntityType()
        {
            return typeof(Stock.Product);
        }
    }
}